package com.rendevous.main;

import java.io.IOException;
import java.util.Scanner;

import org.json.simple.parser.ParseException;

import com.rendevous.utils.Constants;

public class RendevousPlusCommandLineSystem {

	public void run() throws IOException, ParseException {
		listenAndExecuteCommand();
		exitSystem();
	}

	private void listenAndExecuteCommand() throws IOException, ParseException {
		Scanner sc = new Scanner(System.in);
		String userInput;
		ServiceController serviceController = new ServiceController();
		String systemFeedback;
		boolean exitSystemStatus = false;

		showToUser(Constants.MSG_WELCOME);
		while (exitSystemStatus == false) {
			showToUser(Constants.CMD_PROMPT);
			userInput = sc.nextLine();
			serviceController.execute(userInput);
			systemFeedback = serviceController.getSystemFeedback();
			showToUser(systemFeedback);
			exitSystemStatus = serviceController.getExitSystemStatus();
		}
		sc.close();
	}

	private void exitSystem() {
		System.exit(0);
	}

	private void showToUser(String systemFeedback) {
		System.out.println(systemFeedback);
	}
}